package Text9;

import java.util.Scanner;

public class Main {
    //    n−皇后问题是指将n个皇后放在 n×n 国际象棋棋盘上，
//    使得皇后不能相互攻击到，即任意两个皇后都不能处于同一行、同一列或同一斜线上。
    public static int N = 20,n;
    public static char[][] path = new char[N][N];
    public static boolean [] col = new boolean[N];
    public static boolean[] dg = new boolean[N];
    public static boolean[] udg = new boolean[N];
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                path[i][j]='.';
            }
        }
        dfs(0);
    }
    private static void dfs(int x) {
       if(x==n){
           for (int i = 0; i < n; i++) {
               for (int j = 0; j < n; j++) {
                   System.out.print(path[i][j]+" ");
               }
               System.out.println();
           }
           System.out.println();
           return;
       }
        for (int i = 0; i < n; i++) {
            if(!col[i]&&!dg[i+x]&&!udg[n-x+i]){
                path[x][i]='Q';
                col[i]=dg[i+x]=udg[n-x+i]=true;
                dfs(x+1);
                path[x][i]='.';
                col[i]=dg[i+x]=udg[n-x+i]=false;
            }
        }
    }
}
